//
//  PictureSelectorCell.m
//  图片选择器
//
//  Created by zxy on 2019/1/18.
//  Copyright © 2019 zxy. All rights reserved.
//

#import "PictureSelectorCell.h"
@interface PictureSelectorCell()
@property (weak, nonatomic) IBOutlet UIButton *removeBtn;
@property (weak, nonatomic) IBOutlet UIButton *addBtn;

@end
@implementation PictureSelectorCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

-(void)setSelectedImage:(UIImage *)selectedImage{
    _selectedImage = selectedImage;
    if(selectedImage == nil){//显示添加按钮
        [self.addBtn setImage:[UIImage imageNamed:@"compose_pic_add"] forState:UIControlStateNormal];
        [self.addBtn setImage:[UIImage imageNamed:@"compose_pic_add_highlighted"] forState:UIControlStateHighlighted];
        self.removeBtn.hidden = YES;
        self.addBtn.userInteractionEnabled = YES;
    }else{//显示选中图片
        self.addBtn.imageView.contentMode = UIViewContentModeScaleAspectFill;
        [self.addBtn setImage:selectedImage forState:UIControlStateNormal];
        [self.addBtn setImage:nil forState:UIControlStateHighlighted];
        self.removeBtn.hidden = NO;
         self.addBtn.userInteractionEnabled = NO;
    }
}

//删除按钮
- (IBAction)removeBtnClick:(UIButton *)sender {
    if(_delegate && [_delegate respondsToSelector:@selector(removeButtonClick:)]){
        [_delegate removeButtonClick:self];
    }
}

//添加按钮
- (IBAction)addBtnClick:(UIButton *)sender {
    if(_delegate && [_delegate respondsToSelector:@selector(addButtonClick:)]){
        [_delegate addButtonClick:self];
    }
}
@end
